package com.godz.frontData.index2;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.index2ItemMapper;
import com.godz.pojo.index2Item;
import org.springframework.web.bind.annotation.*;
import java.util.List;

//我的项目
@RestController
public class itemData {
    final
    index2ItemMapper itemMapper;

    public itemData(index2ItemMapper itemMapper) {
        this.itemMapper = itemMapper;
    }

    @GetMapping("/index2/get/index2Items")
    public List<index2Item> getItems(){
        return itemMapper.queryAllItem();
    }
    //查询单个
    @GetMapping("/index2/get/index2Item/{intId}")
    public index2Item getOneItem(@PathVariable("intId") Integer integer) {
        return itemMapper.selectOne(
                new QueryWrapper<index2Item>().eq("id", integer)
        );
    }
    //增加一条
    @PostMapping("/index2/post/addItem")
    public String addItem(@RequestBody index2Item item) {
        itemMapper.insert(item);
        return "insert OK";
    }
    //修改一条
    @PostMapping("/index2/post/editItem")
    public String editItem(@RequestBody index2Item item) {
        QueryWrapper<index2Item> wrapper = new QueryWrapper<>();
        wrapper.eq("id", item.getId());

        index2Item item1 = new index2Item();
        item1.setItemName(item.getItemName());
        item1.setItemFirst(item.getItemFirst());
        item1.setItemSecond(item.getItemSecond());
        item1.setItemImg1(item.getItemImg1());
        item1.setItemImg2(item.getItemImg2());

        itemMapper.update(item1, wrapper);
        return "Update OK";
    }
    //删除一条
    @GetMapping("/index2/get/deleteItem/{id}")
    public String deleteItem(@PathVariable("id") Integer integer) {
        itemMapper.deleteById(integer);
        return "Delete Ok";
    }

}
